from pymongo import Connection

class mongoDBPool:
	connection = None 
	db_name = ''
	db_tmp = {}

	@classmethod
	def getConnection(cls):
		if cls.connection == None : 
			cls.connection = Connection();
		return cls.connection[cls.db_name]

	@classmethod
	def Register(cls, dbname, data) :
		cls.db_tmp[dbname] = data;
		db = mongoDBPool.getConnection()
		db[dbname].drop()
		db[dbname].insert(data)
	
	#@classmethod
	#def on(cls) :
		#for x in cls.db_tmp :
			#db = mongoDBPool.getConnection()
			#db[x].drop()
			#db[x].insert(cls.db_tmp[x])

	@classmethod
	def drop(cls) :
		for x in cls.db_tmp :
			db = mongoDBPool.getConnection()
			db[x].drop()


			
def Collection(get_docs) :
	mongoDBPool.Register(dbname = get_docs.__name__, data = get_docs());
	return get_docs;

